<?php


namespace app\controller;

use app\model\Guestbook;
use think\facade\Session;
use think\facade\View;

class Home
{
    //列表展示
    public function home($current=1,$size=20)
    {
        $result = Guestbook::order('id', 'esc')->paginate(['list_rows'=>$size,
            'page'=>$current
        ]);
        View::assign('username',Session::get("username"));
        View::assign('list',$result);
        View::assign('total',$result->total());
        View::assign('lastPage',$result->lastPage());
        View::assign('currentPage',$result->currentPage());
        // 模板输出
        return View::fetch('index');
    }
    //添加
    public function addGuestBook(){
        $book = request()->post();
        $book['client_id']=Session::get('id');
        Guestbook::create($book,['remain_word','client_id','background']);
        return redirect('/');
    }
    //删除
    public function deleteGuestBook($id){
        $client_id =Guestbook::find($id);
        $client_id =$client_id ->getData('client_id');
        if (Session::get('id')==$client_id){
            Guestbook::destroy($id);
            echo "************************************";
        }
        return redirect('/');
    }




}